# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=djbdns
pkgver=1.05
pkgrel=54
pkgdesc="Excellent high-performance DNS services"
url="https://cr.yp.to/djbdns.html"
arch="all"
license="Public-Domain"
subpackages="djbdns-common tinydns tinydns-openrc:tinydns_openrc dnscache
	dnscache-openrc:dnscache_openrc $pkgname-doc"
source="https://cr.yp.to/djbdns/djbdns-$pkgver.tar.gz
https://www.fefe.de/dns/djbdns-1.05-test25.diff.bz2
	headtail.patch
	dnsroots.patch
	dnstracesort.patch
	djbdns-1.05-jumbo-josb.patch
	implicit.patch
	incompatible.patch
	$pkgver-errno.patch
	$pkgver-response.patch
	tinydns.pre-install
	tinydns.initd
	tinydns.confd
	dnscache.initd
	dnscache.confd
	dnscache.monthly
	"
options="!check"

prepare() {
	default_prepare
	# remove all the generated headers. they came with the jumbo patch and should
	# never have been there...
	sed -n 's/^\([a-z0-9]\+\.h\):.*/\1/gp' Makefile Makefile.sig | xargs rm -f
}

build() {
	# sigsetmask
	export CFLAGS="$CFLAGS -DHASSIGPROCMASK"
	echo "${CC:-"gcc"} $CFLAGS" > conf-cc
	echo "${CC:-"gcc"} $LDFLAGS" > conf-ld
	echo "/usr" > conf-home
	make -j1
}

package() {
	install -Dm644 dnsroots.global -t "$pkgdir"/etc/
	install -Dm755 *-conf dnscache tinydns walldns rbldns pickdns axfrdns \
		*-get *-data *-edit dnsip dnsipq dnsname dnstxt dnsmx \
		dnsfilter random-ip dnsqr dnsq dnstrace dnstracesort \
		-t "$pkgdir"/usr/bin/
	mkdir -p "$pkgdir"/usr/share/doc/djbdns
}

common() {
	pkgdesc="Base utilities of djbdns"
	replaces="djbdns"

	amove usr/bin/dnsqr usr/bin/dnsip
}

tinydns() {
	pkgdesc="A small and secure DNS server"
	install=tinydns.pre-install

	amove usr/bin/tinydns*
	mkdir -p "$subpkgdir"/etc/tinydns \
		"$subpkgdir"/var/cache/tinydns
}

tinydns_openrc() {
	depends=
	pkgdesc="A small and secure DNS server (OpenRC init scripts)"
	install_if="openrc ${subpkgname%-openrc}=$pkgver-r$pkgrel"

	install -D -m755 "$srcdir"/tinydns.initd \
		"$subpkgdir"/etc/init.d/tinydns
	install -D -m644 "$srcdir"/tinydns.confd \
		"$subpkgdir"/etc/conf.d/tinydns
}

dnscache() {
	pkgdesc="A recursive resolver"
	install=dnscache.pre-install
	depends=djbdns-common

	mkdir -p "$subpkgdir"/usr/bin \
		"$subpkgdir"/etc/dnscache/ip \
		"$subpkgdir"/etc/dnscache/servers

	cp "$pkgdir"/etc/dnsroots.global "$subpkgdir"/etc/dnscache/servers/@
	touch "$subpkgdir"/etc/dnscache/ip/127

	mv "$pkgdir"/usr/bin/dnscache* "$subpkgdir"/usr/bin
	install -D -m755 "$srcdir"/dnscache.monthly \
		"$subpkgdir"/etc/periodic/monthly/dnscache-hints-refresh
}

dnscache_openrc() {
	depends=
	pkgdesc="A recursive resolver (OpenRC init scripts)"
	install_if="openrc ${subpkgname%-openrc}=$pkgver-r$pkgrel"

	install -D -m755 "$srcdir"/dnscache.initd \
		"$subpkgdir"/etc/init.d/dnscache
	install -D -m644 "$srcdir"/dnscache.confd \
		"$subpkgdir"/etc/conf.d/dnscache
}

sha512sums="
20f066402801d7bec183cb710a5bc51e41f1410024741e5803e26f68f2c13567e48eba793f233dfab903459c3335bc169e24b99d66a4c64e617e1f0779732fa9  djbdns-1.05.tar.gz
41cca597dba971010b9844071e0349d3a4b25cc4b144e12721b0bc8250589fb374e40ece8908f1081762597048179b1177e88b9a5f97be0b47b63e3183e654bb  djbdns-1.05-test25.diff.bz2
be4c9aea40c737364a56f188ad2276d90deac0dffb73ba4b659490836c0fe92ffb65ccf23c6724b913b2d6354336727004be0cf5b43ebc47abe7004700dfe1e8  headtail.patch
0cd97d833e0aaee2b82ed27b56ce183e9ab9806ff1e77bc61b7f38ae3168aa7310b12d2ed330713c4da97e60881ee339f6af449142cc29823865d87270733211  dnsroots.patch
ae9cd51f24041aed135b5ba88d1efd0310b8095bccd6fb60a986756b460a4f98a93e163c3ddae7c146d56a9d41778d17449f772b91fdc58d9e69523cf6c2a6e9  dnstracesort.patch
7612e79638617806425bf6e601dd797f79a0106c47a31c73c88e2504b14e8f0238bad7dc8af1fbc5b1609bfa38578c556dcba2ce9034673bd07c9bc95789ee04  djbdns-1.05-jumbo-josb.patch
b8778f8086edc5703fc0f447ad108bda2e029e612f80c39925833566ff8fa12687bb5300b1f0ee738c7180d4f8269ff88c965bef8879dc6eeea8228a598c10ce  implicit.patch
b676e1b12d025168bbd170770ab2fca87f019aa9e4d3b742b0e3c62f35f3f96880449beaef544f47538bfb7bdfad7b965aee42a055ffcbd732573fb25fb4bc36  incompatible.patch
086d02600034d486f084fd2500aba9041dfa02110781594cdc3781a3ad7823f61f11c54c053c8c1241f58660527abe536906aba0e7f6c49ed3b8dbd74ba8f2b7  1.05-errno.patch
407207f8387e2344fdebe68ab2213adbd9f1e6034e343b4359c8c1fa6ce36b0878a8367e4ee05cb4a44c199d4956aef0c6c8e84ab4f5556178547346ab88b82d  1.05-response.patch
20dd227e4f1362136070d914d5ee41082b5f16ee8602ad591e52b02f03ff0531d0589fff4352fc6799a8c192b69a99af1b013f87ee4ddbdffa03715d33e2f5af  tinydns.pre-install
797671630dd1943a0b0f5fb35ad4972f846752595fb9ddb1f5e4f75db81a59ab23e3f96bc29c814b5fcefdfcd9d55c39aa2835618cad877a74c0707376130aff  tinydns.initd
31b52bd4dd0f78ff63e105ff3937fb9bf582628fe7a04bfcba91195d4fc4b55b60869f993a42ef55a228892647af07ed7ea22cfff72812430c7b8207debdd8f1  tinydns.confd
31bf58ed6a049e02210ce1cbbea00b62e2fe92339cd861eb3ee35f16186a3904e85fcd2f056e2d788b8a284068d83a3767cef01519a6d0152f1958be8e418956  dnscache.initd
1b281a4892c1c9ad39a15c95d0fbd14b0ada69b31723250e33d96946bd19f3edc4b36ec90fb9b6b884d7907b7e86cc3980f116f16fe35fb7496feffd728b1ffa  dnscache.confd
19dcd0880a4e43657d05916b96c1ce075e4ba0a9dc0f7085408e92e087e5a9386ff760e76f81c509fe7402aa6fd9580817f590d5a062dca6bf813d73e0e1b95c  dnscache.monthly
"
